/**
 * 
 */
package com.munoor.dalai.client;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.History;
import com.munoor.dalai.client.presenter.Presenter;

/**
 * @author Osho
 * 
 */
public class AppController implements ValueChangeHandler<String> {
	private final SimpleEventBus eventBus;

	public AppController(SimpleEventBus eventBus) {
		this.eventBus = eventBus;
		bind();
	}

	private void bind() {
		History.addValueChangeHandler(this);

		/*
		 * eventBus.addHandler(FriendAddEvent.TYPE, new FriendAddEventHandler()
		 * { public void onAddFriend(FriendAddEvent event) { doAddNewFriend(); }
		 * });
		 */

	}

/*	private void doAddNewFriend() {
		History.newItem("add");
	}*/

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		String token = event.getValue();
		if (token != null) {
		      Presenter presenter = null;

		      if (token.equals("list")) {
/*		        presenter = getMessageListPresenter();
		        presenter.go(ConnectrApp.get().getMainPanel());
		        
		        return;*/

		      } else if (token.equals("add")) {
		       /* presenter = new FriendEditPresenter(friendService, eventBus, new FriendEditView(), null);
		        presenter.go(ConnectrApp.get().getMainPanel());

		        return;*/

		      } 
		    }

	}
	
	  public void go() {

		    if ("".equals(History.getToken())) {
		      History.newItem("home");
		    } else {
		      History.fireCurrentHistoryState();
		    }
		  }
}
